#include "frmUpdate.h"
#include "ui_frmUpdate.h"
#include <QMessageBox>
#include <QProcess>

frmUpdate::frmUpdate(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::frmUpdate)
{
    setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowMinMaxButtonsHint);
    ui->setupUi(this);
    ui->labValYour->setText(qApp->applicationVersion());
}

frmUpdate::~frmUpdate()
{
    delete ui;
}

void frmUpdate::setNewVersion(QString newVersion)
{
    ui->labValNew->setText(newVersion);
}

void frmUpdate::on_cmdDisableUpdateNotification_clicked()
{
    emit disableUpdateNotification();
    ui->cmdDisableUpdateNotification->setVisible(false);
    ui->cmdInstall->setFocus();
    this->close();
}

void frmUpdate::on_cmdNotNow_clicked()
{
    ui->cmdInstall->setFocus();
    this->close();
}

void frmUpdate::on_cmdInstall_clicked()
{
#ifdef WIN32
    QStringList args;
    args.append("/C");
    args.append("KeppeScriptUpdater.exe --path=network --script=http://msg.keppe.org/update/" + versionType + "_" + ui->labValNew->text() + ".lua --version=" + qApp->applicationVersion());
    QProcess *ksu = new QProcess;
    ksu->startDetached("cmd",args);
    ksu->deleteLater();
    qApp->exit(0);
#elif defined(MACX)
    //Do Mac Update
#else
    QMessageBox::warning(this,QApplication::tr("Keppe Messenger Update"),QApplication::tr("Can't Update on this Platform!"));
    this->close();
#endif
}

void frmUpdate::setVersionType(QString vType)
{
    versionType = vType;
}

void frmUpdate::disableUpdateNotificationButton()
{
    ui->cmdDisableUpdateNotification->setVisible(false);
}

void frmUpdate::enableUpdateNotificationButton()
{
    ui->cmdDisableUpdateNotification->setVisible(true);
}
